{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Box Plot with Min/Max Whiskers\n",
    "------------------------------\n",
    "This example shows how to make a basic box plot using US Population\n",
    "data from 2000.\n",
    "\n",
    "https://vega.github.io/vega-lite/examples/box-plot_minmax_2D_vertical_normalized.html\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import altair as alt\n",
    "alt.data_transformers.enable('json')\n",
    "from vega_datasets import data\n",
    "\n",
    "population = data.population.url\n",
    "\n",
    "# Define aggregate fields\n",
    "lower_box = 'q1(people):Q'\n",
    "lower_whisker = 'min(people):Q'\n",
    "upper_box = 'q3(people):Q'\n",
    "upper_whisker = 'max(people):Q'\n",
    "\n",
    "# Compose each layer individually\n",
    "lower_plot = alt.Chart(population).mark_rule().encode(\n",
    "    y=alt.Y(lower_whisker, axis=alt.Axis(title=\"population\")),\n",
    "    y2=lower_box,\n",
    "    x='age:O'\n",
    ")\n",
    "\n",
    "middle_plot = alt.Chart(population).mark_bar(size=5.0).encode(\n",
    "    y=lower_box,\n",
    "    y2=upper_box,\n",
    "    x='age:O'\n",
    ")\n",
    "\n",
    "upper_plot = alt.Chart(population).mark_rule().encode(\n",
    "    y=upper_whisker,\n",
    "    y2=upper_box,\n",
    "    x='age:O'\n",
    ")\n",
    "\n",
    "middle_tick = alt.Chart(population).mark_tick(\n",
    "    color='white',\n",
    "    size=5.0\n",
    ").encode(\n",
    "    y='median(people):Q',\n",
    "    x='age:O',\n",
    ")\n",
    "\n",
    "lower_plot + middle_plot + upper_plot + middle_tick\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "env": {},
   "interrupt_mode": "signal",
   "language": "python",
   "metadata": {},
   "name": "python3"
  },
  "language": "python"
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
